Skip to content

Close avio object *before* encode destruction. And flush, too. #773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2025

Conversation

NicolasHug
Copy link
Member

The Failed to open input buffer aren't resolved as they were visible in https://github.com/pytorch/torchcodec/actions/runs/16238309871/job/45851804069?pr=757.

So #724 is still a problem, and #755 wasn't a proper fix.

I hope this one is the one. It does 2 things:

  • We now call avio_close() at the end of encode(). Not just when the encoder is destructed. That makes sense.
  • We also now call avio_flush(), which was potentially needed. I'm not entirely sure, but it's probably needed. Or at least it's fairly clear that calling avio_close() isn't enough anyway, because we are seeing the error not just when relying on FFmpeg's default avio object, but also when using to_tensor(): https://github.com/pytorch/torchcodec/actions/runs/16238309871/job/45851804069?pr=757.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 12, 2025
@NicolasHug NicolasHug mentioned this pull request Jul 12, 2025
@NicolasHug
Copy link
Member Author

😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭 😭

https://github.com/pytorch/torchcodec/actions/runs/16241951867/job/45859651025?pr=773

@@ -99,8 +99,18 @@ AVSampleFormat findBestOutputSampleFormat(const AVCodec& avCodec) {
} // namespace

AudioEncoder::~AudioEncoder() {
if (avFormatContext_ && avFormatContext_->pb && !avioContextHolder_) {
avio_close(avFormatContext_->pb);
close_avio();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nite: closeAVIO() for consistency.

@NicolasHug NicolasHug merged commit 784003f into pytorch:main Jul 23, 2025
42 of 45 checks passed
@NicolasHug NicolasHug deleted the aviocloseagain branch July 23, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants